package 线程;
/*
    start方法调用start0(start0方法是一个native方法，由jvm调用，用c或者c++实现，start0根据操作系统不同来实现)方法后，
    该线程不会立马执行，只是将线程变成了可执行状态，具体啥时候执行，取决于CPU，由CPU统一调度
 */
public class 代理模式 {
    public static void main(String[] args) {
        Pig pig = new Pig();
        ThreadProxy threadProxy = new ThreadProxy(pig);
        threadProxy.start();
    }
}

class ThreadProxy implements Runnable{
    private Runnable target = null;

    public ThreadProxy(Runnable target) {
        this.target = target;
    }


    @Override
    public void run() {
        if(target != null){
            target.run();
        }
    }

    public void start(){
        start0();
    }

    private void start0() {
        this.run();
    }
}
class Animal{}
class Pig extends Animal implements Runnable{

    @Override
    public void run() {
        System.out.println("小猪飞起来");
    }
}